package com.dk.controller;

import com.dk.pojo.ABook;
import com.dk.service.ABookServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("aBookController")
public class ABookController {

    @Autowired
    private ABookServiceI aBookServiceI;

    //跳转查询页面
    @RequestMapping("list")
    public String listGet(){
        return "aBook/list";
    }

    //查询
    @RequestMapping("getInfoServer")
    @ResponseBody
    public List<ABook> getInfoServer(){
        List<ABook> list = aBookServiceI.getInfoServer();
        return list;
    }

    //跳转增加页面
    @RequestMapping("insertInfo")
    public String insertInfo(){
        return "aBook/add";
    }

    //确认增加
    @RequestMapping("saveById")
    @ResponseBody
    public int saveById(ABook aBook){
        aBookServiceI.saveById(aBook);
        return 1;
    }

    //跳转回显页面
    @RequestMapping("updateInfo/{bookId}")
    public String updateInfo(@PathVariable("bookId")Integer bookId, Model model){
        ABook aBook = aBookServiceI.getUpdateInfo(bookId);
        model.addAttribute("aBook",aBook);
        return "aBook/update";
    }
    //确认修改
    @RequestMapping("updateById")
    @ResponseBody
    public int updateById(ABook aBook){
        aBookServiceI.updateById(aBook);
        return 1;
    }

    //确认删除
    @RequestMapping("deleteById/{bookId}")
    @ResponseBody
    public int deleteById(@PathVariable("bookId")Integer bookId){
        aBookServiceI.deleteById(bookId);
        return 1;
    }
}
